﻿#region
/*******************************************************************************
** File Name:		    WineShopInfoService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class WineShopInfoService : IWineShopInfoService
    {
		 IWineShopInfo wineShopInfo = new WineShopInfoRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByWineShopInfoID (WineShopInfoModel model)
		{
			EWineShopInfo entity = ConvertModelToEntity(model);

            wineShopInfo.UpdateByWineShopInfoID(entity);

		}

		public void DeleteByWineShopInfoID (System.Int64 wineShopInfoID)
		{
		
            wineShopInfo.DeleteByWineShopInfoID(wineShopInfoID);

		}
		 
        public WineShopInfoModel GetByWineShopInfoID (System.Int64 wineShopInfoID)
        {
        
			EWineShopInfo entity = wineShopInfo.GetByWineShopInfoID(wineShopInfoID);
			
            WineShopInfoModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<WineShopInfoModel> GetAll ()
		{
			IList<EWineShopInfo> entity = wineShopInfo.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<WineShopInfoModel> list = new List<WineShopInfoModel>();

            foreach (var item in entity)
            {
                WineShopInfoModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private WineShopInfoModel ConvertEntityToModel(EWineShopInfo entity)
		{
			if (entity == null)
            {
                return null;
            }
			WineShopInfoModel model = new WineShopInfoModel();
                        model.WineShopInfoID = entity.WineShopInfoID;
                        model.Name = entity.Name;
                        model.Telephone = entity.Telephone;
                        model.LinkMan = entity.LinkMan;
                        model.Address = entity.Address;
                        model.ImagePath = entity.ImagePath;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private EWineShopInfo ConvertModelToEntity(WineShopInfoModel model)
		{
			if (model == null)
            {
                return null;
            }
			EWineShopInfo entity = new EWineShopInfo();
                        entity.WineShopInfoID = model.WineShopInfoID;
                        entity.Name = model.Name;
                        entity.Telephone = model.Telephone;
                        entity.LinkMan = model.LinkMan;
                        entity.Address = model.Address;
                        entity.ImagePath = model.ImagePath;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}